package U2;

import java.util.Arrays;
import java.util.Scanner;


public class Test1 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()) {
			int n = sc.nextInt();
			int []nums = new int[n];
			for(int i = 0;i < n;i ++) {
				nums[i] = sc.nextInt();
			}
			int flag = sc.nextInt();
			Arrays.sort(nums);
			if(flag == 1) {
				int cnt = 0;
				for(int i = n - 1;i >= 1;i --) {
					System.out.printf("%d ",nums[i]);
				}
				System.out.println(nums[0]);
				
			}else {
				for(int i = 0;i < n - 1;i ++) {
					System.out.printf("%d ",nums[i]);
				}
				System.out.println(nums[n-1]);
			}
				
		}
	}

}
